﻿<common:LayoutAwarePage x:Class="Mutzl.Samples.MapApp.View.MapView"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:behaviors="using:Win8nl.Behaviors"
                        xmlns:bing="using:Bing.Maps"
                        xmlns:common="using:Mutzl.Samples.MapApp.Common"
                        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                        xmlns:mapExtensions="using:Mutzl.Samples.MapApp.MapExtensions"
                        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                        xmlns:winRtBehaviors="using:WinRtBehaviors"
                        x:Name="PageRoot"
                        DataContext="{Binding Map,
                                              Source={StaticResource Locator}}"
                        mc:Ignorable="d">


    <common:LayoutAwarePage.Resources>

        <DataTemplate x:Key="FinanzamtTemplate">
            <Grid HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  mapExtensions:MapExtensions.Location="{Binding Location}">
                <winRtBehaviors:Interaction.Behaviors>
                    <behaviors:EventToBoundCommandBehavior Command="{Binding DataContext.GoToDetailCommand,
                                                                             ElementName=MapControl}"
                                                           CommandParameter="{Binding KurzZeichen}"
                                                           Event="Tapped" />
                </winRtBehaviors:Interaction.Behaviors>
                <ToolTipService.ToolTip>
                    <StackPanel>
                        <Image Source="{Binding Image}" />
                        <TextBlock Text="{Binding Name}" />
                    </StackPanel>
                </ToolTipService.ToolTip>
                <Border Height="24"
                        MinWidth="40"
                        MaxWidth="100"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Background="Green"
                        CornerRadius="10"
                        Padding="5">
                    <TextBlock Foreground="White"
                               Text="{Binding Id}"
                               TextAlignment="Center" />
                </Border>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="SonderObjektTemplate">
            <Grid Width="30"
                  Height="30"
                  ToolTipService.ToolTip="{Binding Name}"
                  mapExtensions:MapExtensions.Latitude="{Binding Latitude}"
                  mapExtensions:MapExtensions.Longitude="{Binding Longitude}">

                <Ellipse Fill="HotPink" />
                <TextBlock VerticalAlignment="Center"
                           Foreground="White"
                           Text="{Binding Id}"
                           TextAlignment="Center" />
            </Grid>
        </DataTemplate>

    </common:LayoutAwarePage.Resources>
    <common:LayoutAwarePage.BottomAppBar>
        <AppBar>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Horizontal" />
                <StackPanel Grid.Column="1"
                            HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <Button VerticalAlignment="Center"
                            AutomationProperties.Name="Zentrieren"
                            Command="{Binding CenterToCurrentLocationCommand}"
                            Style="{StaticResource PinAppBarButtonStyle}" />
                    <Button VerticalAlignment="Center"
                            AutomationProperties.Name="Alle Anzeigen"
                            Command="{Binding ZoomToFitCommand}"
                            Style="{StaticResource FullScreenAppBarButtonStyle}" />
                </StackPanel>
            </Grid>
        </AppBar>
    </common:LayoutAwarePage.BottomAppBar>

    <Grid Background="{StaticResource MainColor}" Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!--  Back button and page title  -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="BackButton"
                    Click="GoBack"
                    IsEnabled="{Binding Frame.CanGoBack,
                                        ElementName=PageRoot}"
                    Style="{StaticResource BackButtonStyle}" />
            <TextBlock x:Name="PageTitle"
                       Grid.Column="1"
                       Style="{StaticResource PageHeaderTextStyle}"
                       Text="{StaticResource AppName}" />
        </Grid>


        <bing:Map x:Name="MapControl"
                  Grid.Row="1"
                  Credentials="{Binding MapsKey}"
                  mapExtensions:MapExtensions.Center="{Binding Center}"
                  mapExtensions:MapExtensions.Zoom="{Binding Zoom}">

            <bing:MapItemsControl ItemTemplate="{StaticResource FinanzamtTemplate}" ItemsSource="{Binding Finanzaemter}" />

            <bing:MapItemsControl ItemTemplate="{StaticResource SonderObjektTemplate}"
                                  ItemsSource="{Binding SonderObjekte}"
                                  Visibility="{Binding Settings.ShowSonderObjekte,
                                                       Source={StaticResource Locator},
                                                       Converter={StaticResource BooleanToVisiblityConverter}}" />


        </bing:Map>


        <VisualStateManager.VisualStateGroups>

            <!--  Visual states reflect the application's view state  -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape" />
                <VisualState x:Name="Filled" />

                <!--  The entire page respects the narrower 100-pixel margin convention for portrait  -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--  The back button and title have different styles when snapped  -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
